export default {
  namespaced: true,
  state: {
    token: localStorage.getItem('token'),
    name: '',
    avatar: ''
  },
  mutations: {
    SET_TOKEN(state, token) {
      state.token = token
    },
    SET_NAME(state, name) {
      state.name = name
    },
    SET_AVATAR(state, avatar) {
      state.avatar = avatar
    }
  },
  actions: {
    login({ commit }) {
      return new Promise((resolve) => {
        commit('SET_TOKEN', 'test-token')
        localStorage.setItem('token', 'test-token')
        resolve()
      })
    },
    logout({ commit }) {
      return new Promise((resolve) => {
        commit('SET_TOKEN', '')
        localStorage.removeItem('token')
        resolve()
      })
    }
  }
}
